// reducer action api 交流
import axios from 'axios';
import { useDispatch } from 'react-redux'

/* 
    axios专门负责数据请求
    axios --> useDispatch --> reducer 重新运行 
*/

const http = axios.create({
    baseURL: "https://cnodejs.org/api/v1",
})

function useUser() {
    let dispatch = useDispatch();
    return function (loginname) {
        dispatch({
            type: "user_loading"
        })
        http.get(`/user/${loginname}`)
            .then((res) => {
                console.log(res)
                dispatch({
                    type: "user_loadover",
                    data: res.data.data
                })
            })
    }
}

export {
    useUser
}
